package com.java.project.system.prov.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.java.framework.aspectj.lang.annotation.Log;
import com.java.framework.aspectj.lang.enums.BusinessType;
import com.java.project.system.prov.domain.Prov;
import com.java.project.system.prov.service.IProvService;
import com.java.framework.web.controller.BaseController;
import com.java.framework.web.domain.AjaxResult;
import com.java.common.utils.poi.ExcelUtil;
import com.java.framework.web.page.TableDataInfo;

/**
 * 省Controller
 * 
 * @author admin_wjz
 * @date 2019-10-29
 */
@Controller
@RequestMapping("/system/prov")
public class ProvController extends BaseController
{
    private String prefix = "system/prov";

    @Autowired
    private IProvService provService;

    @RequiresPermissions("system:prov:view")
    @GetMapping()
    public String prov()
    {
        return prefix + "/prov";
    }

    /**
     * 查询省列表
     */
    @RequiresPermissions("system:prov:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Prov prov)
    {
        startPage();
        List<Prov> list = provService.selectProvList(prov);
        return getDataTable(list);
    }

    /**
     * 导出省列表
     */
    @RequiresPermissions("system:prov:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Prov prov)
    {
        List<Prov> list = provService.selectProvList(prov);
        ExcelUtil<Prov> util = new ExcelUtil<Prov>(Prov.class);
        return util.exportExcel(list, "prov");
    }

    /**
     * 新增省
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存省
     */
    @RequiresPermissions("system:prov:add")
    @Log(title = "省", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Prov prov)
    {
        return toAjax(provService.insertProv(prov));
    }

    /**
     * 修改省
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        Prov prov = provService.selectProvById(id);
        mmap.put("prov", prov);
        return prefix + "/edit";
    }

    /**
     * 修改保存省
     */
    @RequiresPermissions("system:prov:edit")
    @Log(title = "省", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Prov prov)
    {
        return toAjax(provService.updateProv(prov));
    }

    /**
     * 删除省
     */
    @RequiresPermissions("system:prov:remove")
    @Log(title = "省", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(provService.deleteProvByIds(ids));
    }
}
